package com.zbkj.service.util;

import java.time.LocalDateTime;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

public class MonthRangeUtil {
    
    private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    
    public static class MonthRange {
        private final String start;
        private final String end;
        
        public MonthRange(String start, String end) {
            this.start = start;
            this.end = end;
        }
        
        public String getStart() {
            return start;
        }
        
        public String getEnd() {
            return end;
        }
        
        @Override
        public String toString() {
            return "Start: " + start + ", End: " + end;
        }
    }
    
    public static MonthRange getMonthStartEnd(String yearMonth) {
        try {
            // 解析年月
            YearMonth ym = YearMonth.parse(yearMonth);
            
            // 获取当月第一天 00:00:00
            LocalDateTime start = ym.atDay(1).atStartOfDay();
            
            // 获取当月最后一天 23:59:59
            LocalDateTime end = ym.atEndOfMonth().atTime(23, 59, 59);
            
            return new MonthRange(
                start.format(FORMATTER),
                end.format(FORMATTER)
            );
        } catch (DateTimeParseException e) {
            throw new IllegalArgumentException("日期格式应为 yyyy-MM", e);
        }
    }
    

}